/**
 * 自定义指令文件
 */
import { useSystem } from '@/pinia';
import { Directive, DirectiveBinding } from 'vue';
interface Throttle {
    click: (...args:any) => void
    time:number
}
// 自定义节流指令
export const vThrottle: Directive = (el: HTMLElement, binding: DirectiveBinding<Throttle>) => {

    let timer:any = null
    
    let time = binding.value.time || 2000

    el.addEventListener('click', () => {
            
            if (timer) return

            binding.value.click()
   
            timer = setTimeout(() => {
                clearTimeout(timer)
                timer = null
            }, time);
        
    })
}


// 校验按钮权限指令
export const vPermission = (el:HTMLElement,binding:any)=>{
    const SystemStore = useSystem()
    const {value} = binding
    if (!SystemStore.permission.includes(value)) {
        el.parentNode?.removeChild(el)
    }
}


